package com.custom.base.view

import android.content.Context
import android.util.AttributeSet
import android.widget.EditText
import com.custom.base.R
import com.custom.base.util.SDTimerUtil

class EditTextPromptErrorView(context: Context, attrs: AttributeSet?) : androidx.appcompat.widget.AppCompatEditText(context, attrs) {
    private var error = false
    private var timeUtil:SDTimerUtil = SDTimerUtil()
    init {
        background = null
    }


    fun error(){
        error = true
        startTime()
    }

    private fun startTime(){
        if(error){
            background = context.resources.getDrawable(R.drawable.frame_red)
            if(timeUtil.isWorking) timeUtil.stopWork()
            timeUtil.startWork(1000,object :SDTimerUtil.SDTimerListener{
                override fun onWork() {
                    error = false
                    startTime()
                }
                override fun onWorkMain() {}
            })
        }else{
            background = null
        }
    }
}